package com.allwees.bs.module.core.dynamic.strategy.moudule;

import com.allwees.bs.core.model.order.entity.OrderModel;
import com.allwees.bs.module.core.dynamic.data.DynamicInjectQuery;
import com.allwees.bs.module.core.dynamic.model.ShippingAddressSnap;
import com.allwees.bs.module.core.dynamic.strategy.DynamicInjectStrategy;
import com.allwees.core.common.util.DynamicFieldUtil;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Setter
public class DynamicInjectShippingAddressStrategy extends DynamicInjectStrategy {

    private DynamicInjectQuery query;

    @Override
    public Object inject(String key, Object target) {
        OrderModel order = query.findShippingAddressByKey(key);
        if (order == null) {
            return target;
        }

        Map<String, Object> map = new HashMap<>();
        map.put("shippingAddress", new ShippingAddressSnap(order));

        return DynamicFieldUtil.getTarget(target, map);
    }
}
